<?php


include 'lib/utiles.php';


$patrones = array(
    array(0,1,1),
    array(1,0,1),
    array(1,1,0),
    array(0,0,0)
);


$Wji = array(
    array(0.1, 0.5),
    array(-0.7, 0.3)

);

$Wkj = array(
    array(0.2),
    array(0.4)
);

$error = array();

//for ($j = 0; $j < 200; $j++) {

$n = count($patrones);
for ($i = 0; $i < $n; $i++) {
    //echo $ts =  $patrones[$i][1]; die;
    $y0 = sigmoidea( $Wji[0][0] * $patrones[$i][0] + $Wji[1][0] * $patrones[$i][1] );

    $y1 = sigmoidea($Wji[0][1] * $patrones[$i][0] + $Wji[1][1] * $patrones[$i][1] );

    $z0 = sigmoidea($Wkj[0][0] * $y0 + $Wkj[1][0] * $y1);
    
    echo "Se hizo la propagacion hacia adelante <br /> y0=$y0 <br/> y1=$y1<br/> z0=$z0 <br /><br />";
    
    //Para cada "salida"...
    $e0 =  $patrones[$i][2] - $z0;
    $error[] = $e0;
    echo "Error en la salida e0=t0-z0= $e0 <br />------------------------------------<br /><br />";
    echo "Ajustando los pesos en la capa output<br />";
    
    printe($Wkj);
    
    $deltak = $z0*(1-$z0)*($patrones[$i][2]-$z0);
    
    $Wkj[0][0] = $Wkj[0][0] + 0.25 * $y0 * $deltak; 
    $Wkj[1][0] = $Wkj[1][0] + 0.25 * $y1 * $deltak;
    
    printe($Wkj);
    
    
    echo "Ajustando los pesos en la capa hidden<br /><br />";
    
    $suma0 = $Wkj[0][0]*$deltak;
    $suma1 =  $Wkj[1][0]*$deltak;
     
    printe($Wji);
    $Wji[0][0] = $Wji[0][0] + 0.25 * $y0 * (1-$y0) * $suma0 ;
    $Wji[1][0] = $Wji[1][0] + 0.25 * $y0 * (1-$y0) * $suma1 ;
    $Wji[0][1] = $Wji[0][1] + 0.25 * $y0 * (1-$y0) * $suma0 ;
    $Wji[1][1] = $Wji[1][1] + 0.25 * $y0 * (1-$y0) * $suma1 ;
    printe($Wji);
    
    
    
    


//}

}

printe($error);


